<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>开始使用layui</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="div-index"></div>
<form class="layui-form"  id="demoEdit"  method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="title" autocomplete="off"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" name="content" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn"  id="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="10">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>用户名</th>
            <th>留言内容</th>
        </tr>
        </thead>
        <tbody>
        {volist name='info' id='vo'}
        <tr>
            <td>{$vo.username}</td>
            <td>{$vo.content}</td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>

<script src="/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','layedit','jquery'], function(){
        var layer = layui.layer
            ,layedit = layui.layedit
            ,$ = layui.jquery
            ,form = layui.form;
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

       $("#demo1").on("click",function () {
          // alert('ok');
           $.post("{:url('add')}",$('#demoEdit').serialize(),function (data) {
               if (data.status==1)
               {
                   layer.alert(data.msg, {
                       skin: 'layui-layer-molv' //样式类名
                       ,closeBtn: 0
                       ,anim: 6 //动画类型
                   });
                  // window.location.href="{:url('index/ok')}"

               }else
               {
                   alert(0);
               }
           })
       })

    });


</script>
</body>
</html>